import json
import boto3


def lambda_handler(event, context):
    # TODO implement

    userInput = json.loads(event['body'])['messages'][0]['unstructured']['text']

    client = boto3.client('lex-runtime')

    response = client.post_text(
        botName='ChatBot',
        botAlias='Prod',
        sessionAttributes={
        },
        requestAttributes={
        },
        userId=event['requestContext']['accountId'],
        inputText=userInput
    )

    return {
        'headers': {
            'Access-Control-Allow-Origin': '*'
        },
        'body': json.dumps({'messages': [{'type': "unstructured", 'unstructured': {'text': response['message']}}]})
    }